﻿using System;
using System.ComponentModel;
using System.Reflection;

namespace Bimaru
{
    internal class Cell
    {
        private CellOccupant Shown { get; set; }
        private Guid? Hidden { get; set; }
        public bool IsEnd { get; set; }
        private bool IsLocked { get; set; }

        public Cell()
        {
            Shown = default(CellOccupant);
        }

        public Cell(Guid hGuid)
        {
            Hidden = hGuid;
        }

        public Cell(bool isLocked, Guid hGuid)
        {
            IsLocked = isLocked;
            Hidden = hGuid;
            Shown = default(CellOccupant);
        }

        public CellOccupant RotateOccupant()
        {
            if (!IsLocked)
            {
                Shown = NextOccupant(Shown);
            }
            else
            {
                throw new AttemptToChangeLockedCell();
            }
            return Shown;
        }

        public CellOccupant NextOccupant(CellOccupant occupant)
        {
            return occupant.NextOccupant();
        }

        public bool IsMatch()
        {
            return (Shown == CellOccupant.Ship && Hidden != null) || (Shown == CellOccupant.Water && Hidden == null);
        }

    }
}